import { createRouter, createWebHistory } from 'vue-router'
// import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect:'/login'
    },
    {
      path: '/login',
      name: 'Login',
      meta:{
        title:"登录"
     },
      component: () => import('../views/Login.vue')
    },
    {
      path: '/index',
      name: 'Index',
      component: () => import('../views/Index.vue'),
      redirect:'/index/system',
      children:[
         {
          path: 'system',// /index/system
          name: 'System',
          meta:{
            title:"系统介绍"
         },
          component: () => import('../views/Dashboard/System.vue'),
         },
         {
          path: 'dashboard',// /index/system
          name: 'Dashboard',
          meta:{
            title:"Dashboard"
         },
          component: () => import('../views/Dashboard/Dashboard.vue'),
         },
         {
          path: 'addDoods',// /index/system
          name: 'AddDoods',
          meta:{
            title:"添加商品"
         },
          component: () => import('../views/Dashboard/AddDoods.vue'),
         },
         {
          path: 'loopimg',// /index/system
          name: 'Loopimg',
          meta:{
            title:"轮播图配置"
         },
          component: () => import('../views/IndexSet/Loopimg.vue'),
         },
         {
          path:"category",
          name:"Category",
          meta:{
            title:"分类管理"
         },
          component:()=>import("../views/Modulemanger/Category.vue")
         },
         {
          path:"user",
          name:"User",
          meta:{
            title:"修改密码"
         },
          component:()=>import("../views/Systemmanger/user.vue")
         }

        
      ]
    },
    {
     path: '/:pathMatch(.*)*', 
    name: 'NotFound', 
    component: ()=>import('../views/NotFound.vue')
   },
  ]
})

router.beforeEach((to,from,next)=>{//前置守卫
  document.title=to.meta.title
   let token=localStorage.getItem("token");
   if(!token&&to.path!="/login"){// 没有登录token  不在登录页面去登录页面
      next("/login")
   }else{

     next()
   }

})

export default router
